package de.dhbw.karlsruhe.picsim.model.commands.impl;

import de.dhbw.karlsruhe.picsim.model.actions.ActionFactory;
import de.dhbw.karlsruhe.picsim.model.actions.PicAction;
import de.dhbw.karlsruhe.picsim.model.memory.RegisterValue;
import de.dhbw.karlsruhe.picsim.model.memory.impl.RegisterValueImpl;
import de.dhbw.karlsruhe.picsim.util.Bits;
import de.dhbw.karlsruhe.picsim.util.impl.BitUtilities;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: goesen
 * Date: May 3, 2010
 * Time: 1:38:19 PM
 */
public class SwapF extends InstructionSupport {
    private static final Log log = LogFactory.getLog(SwapF.class);

    public SwapF(final Bits argument, final boolean targetIsWRegister) {
        super(targetIsWRegister, false, argument);
    }

    @NotNull
    @Override
    protected RegisterValue getValue(@NotNull final RegisterValue addressedFile, @NotNull final RegisterValue wRegister,
                                     @NotNull final List<PicAction> yourActions,
                                     @NotNull final ActionFactory actionFactory) {
        log.debug("SwapF gets executed");
        final Bits low = BitUtilities.subBits(addressedFile, 0, 4);
        final Bits high = BitUtilities.subBits(addressedFile, 4, 8);
        final Bits result = BitUtilities.concat(high, low);
        log.debug("Result is = " + result);
        return new RegisterValueImpl(result);
    }
}
